package com.bxs.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bxs.dao.db.SaveMsgToDBHandler;
import com.bxs.global.JsonResult;
import com.bxs.mapper.RecordMapper;
import com.bxs.pojo.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class RecordController {
    @Autowired
    RecordMapper recordMapper;

    // 查询日志记录列表
    @GetMapping("record-list")
    public JsonResult getRecords(@RequestParam Map<String, String> param){
        System.out.println("filter param");
        QueryWrapper<Record> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("updated_time");

        List<Record> records = recordMapper.selectList(queryWrapper);
        return JsonResult.success(records);
    }

    @GetMapping("record-delete")
    // 删除日志记录
    public JsonResult deleteRecord(@RequestParam Map<String, Object> param){
        Integer id = Integer.valueOf((String)param.get("id"));
        int i = recordMapper.deleteById(id);
        Map<String, Object> res = new HashMap<>();
        res.put("count", i);
        res.put("data", null);
        return JsonResult.success(res);
    }
}
